package org.example.sort;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

public class insertion_sorting {
    public static void main(String[] args) {
        //插入排序
        
        int[] arr = {5,2,4,6,1,3};

        long startTime = System.currentTimeMillis();
        //拿出
        for (int i = 1; i < arr.length; i++) {
            int j = i;
            //比对插入
            while(j > 0){
                if (arr[j] < arr[j-1]){
                    int temp = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = temp;
                }else {
                    break;
                }
                j--;
            }
        }
        long endTime = System.currentTimeMillis();

        System.out.println(Arrays.toString(arr));
        long time = endTime - startTime;
        System.out.println("耗时："+time);
    }
}
